package com.hooya.fa.eu.biz.dao.repository.impl;

import com.hooya.fa.eu.api.dto.PlInvoiceQueryDTO;
import com.hooya.fa.eu.biz.dao.entity.PlInvoice;
import com.hooya.fa.eu.biz.dao.mapper.PlInvoiceMapper;
import com.hooya.fa.eu.biz.dao.repository.PlInvoiceRepository;
import com.hooya.fa.eu.biz.dao.wrapper.PlInvoiceWrapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @Description 1
 * @Author : Zongz
 * @Copyright Copyright (c) 豪雅集团
 * @Create 2023/12/6
 * @Version 1.0.0
 */
@Slf4j
@Repository
@AllArgsConstructor
public class PlInvoiceRepositoryImpl implements PlInvoiceRepository {

    private final PlInvoiceMapper plInvoiceMapper;

    @Override
    public List<PlInvoice> getNeedPLInvoicingData() {
        return plInvoiceMapper.selectList(PlInvoiceWrapper.newQuery().eqSyncStatus(1).neCorrection());
    }

    @Override
    public void batchUpdate(List<PlInvoice> updateInvoiceData) {
        if (CollectionUtils.isEmpty(updateInvoiceData)) {
            return;
        }
        for (PlInvoice invoice : updateInvoiceData) {
            plInvoiceMapper.updateById(invoice);
        }
    }

    @Override
    public List<PlInvoice> getFinishedList() {
        return plInvoiceMapper.selectList(PlInvoiceWrapper.newQuery().eqSyncStatus(2));
    }

    @Override
    public List<PlInvoice> getList() {
        return plInvoiceMapper.selectList(null);
    }

    @Override
    public List<PlInvoice> getErrorInvoiceType() {
        return plInvoiceMapper.getErrorInvoiceType();
    }

    @Override
    public List<PlInvoice> getByCreateTime(String date) {
        return plInvoiceMapper.getByCreateTime(date);
    }

    @Override
    public List<PlInvoice> getPlInvoicedListByDate(String startDate, String endDate) {
        return plInvoiceMapper.getPlInvoicedListByDate(startDate, endDate);
    }

    @Override
    public List<PlInvoice> getCorrectionInvoiceByDate(String startDate, String endDate) {
        return plInvoiceMapper.selectList(PlInvoiceWrapper.newQuery().eqSyncStatus(1).eqCorrection()
                .geSellDate(startDate).ltSellDate(endDate));
    }

    @Override
    public List<PlInvoice> getOriginInvoiceByCondition(List<String> originInvoiceNumberList, String startDate, String endDate) {
        return plInvoiceMapper.selectList(PlInvoiceWrapper.newQuery().eqSyncStatus(2).inInvoiceNumber(originInvoiceNumberList)
                .geSellDate(startDate).ltSellDate(endDate));
    }

    @Override
    public List<PlInvoice> getListByCondition(PlInvoiceQueryDTO query) {
        return plInvoiceMapper.getListByCondition(query);
    }
}
